<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/4/16
 * Time: 0:19
 */
function getTeacher($groupId, $conn)
{


    $sql = "select teacherName from teacher where teacherId in (select
 teacherId from teacherasigntable WHERE groupId=$groupId)";
    $result = mysqli_query($conn, $sql);
    $text = "";
    while ($row = $result->fetch_assoc()) {
        $text .= $row["teacherName"] . "、";
    }

    echo $text;

}

function getStudent($groupId, $conn)
{
    $sql = "select studentName from student where groupID='$groupId'";
    $result = mysqli_query($conn, $sql);
    $text = "";
    while ($row = $result->fetch_assoc()) {
        $text .= $row["studentName"] . "、";
    }
    echo $text;
}

function addOption($name, $id, $table, $groupId, $conn)
{
    if ($table == "teacher") {
        $sql = "select $name,$id from $table where teacherId in (select
        teacherId from teacherasigntable WHERE groupId=$groupId)";

    } else {
        $sql = "select $name,$id from $table where groupId=$groupId";
    }
    $result = mysqli_query($conn, $sql);
    while ($row = $result->fetch_array()) {
        echo "<option value=$row[1]>$row[0]($row[1])</option>";
    }

}

function getAsgin($groupId, $conn)
{

    $sql = "select teacherName,teacherId from teacher
where teacherId in (select teacherId FROM
teacherasigntable where groupId=$groupId)";
    $result = mysqli_query($conn, $sql);
    while ($Trow = $result->fetch_assoc()) {
        echo "<tr></tr><td width='30%'>" . $Trow["teacherName"] . "</td>";
        $teacherId = $Trow["teacherId"];
        $sql = "select studentName from student s join
project p on s.studentId=p.student_studentId
join thesismark t on p.projectId=t.project_projectId
where s.groupId=$groupId and t.teacher_teacherId=$teacherId";
        $result1 = mysqli_query($conn, $sql);
        $text = "";
        while ($Srow = $result1->fetch_assoc()) {
            $text .= $Srow["studentName"] . "、";
        }
        echo "<td>$text</td></tr>";
    }


}


?>